import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jinke/page/pro_list/subs/pro_detail/model/pro_detail_model/pro_detail_model.dart';
import 'package:jinke/utils/component/page_state/widgets/widgets.dart';
import 'package:jinke/utils/util.dart';

import 'index.dart';
import 'widgets/cell.dart';

class ProInventoryPage extends StatelessWidget {
  ProInventoryPage({Key? key, this.mod}) : super(key: key) {
    controller.state.mod = mod;
    controller.getTabs();
  }
  final ProDetailModel? mod;
  final controller = Get.put(ProInventoryController());
  // 主视图
  Widget _buildView() {
    var state = controller.state;
    return Column(
      children: [
        Container(
          height: 60.r,
          child: Row(
            children: [
              Expanded(
                  child: SizedBox(
                height: 26.r,
                child: GridView.builder(
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 1,
                    childAspectRatio: 0.3,
                    mainAxisSpacing: 20.r,
                  ),
                  scrollDirection: Axis.horizontal,
                  itemBuilder: ((context, index) {
                    var tab = controller.state.tabs![index];
                    return InkWell(
                      onTap: () {
                        controller.onTabTap(index);
                      },
                      child: Container(
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            color: state.tabIndex == index
                                ? ColorsUtil.blue
                                : Colors.white,
                            borderRadius: BorderRadius.circular(4.r)),
                        child: Text(
                          '${tab.personTypeName ?? ''}(${tab.cou ?? 0})',
                          style: TextStyle(
                            color: state.tabIndex == index
                                ? Colors.white
                                : ColorsUtil.title,
                            fontSize: 12.sp,
                          ),
                        ),
                      ),
                    );
                  }),
                  itemCount: controller.state.tabs?.length ?? 0,
                ),
              )),
              RichText(
                  text: TextSpan(
                      text: '共',
                      style:
                          TextStyle(color: ColorsUtil.title, fontSize: 13.sp),
                      children: const [
                    TextSpan(
                        text: '3', style: TextStyle(color: ColorsUtil.blue)),
                    TextSpan(
                        text: '项', style: TextStyle(color: ColorsUtil.title)),
                  ]))
            ],
          ),
        ),
        Expanded(
          child: state.list?.length == 0
              ? EmptyView()
              : ListView.builder(
                  itemBuilder: ((context, index) {
                    var mod = state.list![index];
                    return ProInventoryCell(
                      mod: mod,
                    );
                  }),
                  itemCount: state.list?.length ?? 0,
                ),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ProInventoryController>(
      id: "pro_inventory",
      builder: (_) {
        return Scaffold(
          body: Padding(
            padding: EdgeInsets.symmetric(horizontal: 16.r),
            child: _buildView(),
          ),
          floatingActionButtonLocation:
              FloatingActionButtonLocation.centerDocked,
          floatingActionButton: Container(
            margin: EdgeInsets.only(bottom: 80.r),
            alignment: Alignment.bottomRight,
            child: InkWell(
              onTap: () {
                Get.toNamed(RouterPath.create_task)!.then((value) {
                  if (value != null) {
                    controller.getList();
                  }
                });
              },
              child: Container(
                width: 93.r,
                height: 40.r,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  gradient: const LinearGradient(
                    colors: [
                      Color(0xff00A9FE),
                      Color(0xff0173FE),
                    ],
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight,
                  ),
                  borderRadius: BorderRadius.horizontal(
                    left: Radius.circular(20.r),
                  ),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Icon(
                      Icons.add,
                      color: Colors.white,
                      size: 20.r,
                    ),
                    Text(
                      '建任务',
                      style: TextStyle(color: Colors.white, fontSize: 15.r),
                    )
                  ],
                ),
              ),
            ),
          ),
        );
      },
    );
  }
}
